<?php
class ManageMenuEditForm extends Form
{
	var $hotel = array();

    function ManageMenuEditForm()
    {
        Form::Form("ManageBoothForm");

        $id 		= Url::get("id");

        if($id)
        {
        	$this->hotel = Db_Menu::getMenuById($id);
        }

        if(!$this->hotel)
        {
        	Url::redirect_current();
        }

       /* //Check quyền
		if(!User::have_permit("hotel_edit"))
        {
        	//$hotel_ids = Db_Hotel::get_hotel_ids(User::id());

        	if(!Db_Booth::have_permit_manage($this->hotel, User::id()))
	        {
	        	Url::access_denied();
	        }
        }*/
        #############################################################################

        $this->link_css("style/paging.css");
        $this->link_css('style/jquery-ui-1.9.2.custom.css');
        $this->link_css('style/msgBoxLight.css');
        $this->link_css("style/hotel.css");
        $this->link_js('javascript/jquery/jquery-ui-1.9.2.custom.min.js');
        //
        $this->link_js("javascript/jquery/jquery.ui.core.js");
        $this->link_js("javascript/jquery/jquery.ui.widget.js");
        $this->link_js("javascript/jquery/jquery.ui.mouse.js");
        $this->link_js("javascript/jquery/jquery.ui.sortable.js");
        $this->link_js("javascript/jquery/jquery.ui.datepicker.js");
        $this->link_js("javascript/jquery/jquery.msgBox.js");
        $this->link_js("javascript/hotelform.js");

        $this->link_outside_js("http://maps.google.com/maps/api/js?sensor=false");
        $this->link_js("javascript/map/geocoder_tool.js");
        $this->link_css("style/map/geocoder_tool.css");
    }

    function on_submit()
    {
        $hotel['name'] 			    = Url::getParam('hotel_name', '');
        mb_internal_encoding("UTF-8");
        $hotel['name']          = mb_strtoupper(mb_substr($hotel['name'],0,1)) . mb_substr($hotel['name'],1);
        $hotel['slug'] = String::safe_title($hotel["name"]);
        $hotel['status'] 		= (int)Url::get('hotel_status', 0);
        $hotel['pos'] 		    = (int)Url::get('hotel_pos', 0);

        $valid = true;
        if($hotel['name']=='')
        {
            $valid = false;
            $this->setFormError("error_name","Tên Menu không được để trống!");
        }



        if($valid)
        {
            $id = Url::get('id');
            if($idHotel = Db_Menu::update($hotel,$id))//Thanh cong
            {
                $this->setFormSucces("success","Save hành công!");
                Url::redirect_current();
            }
            else
            {
                $this->setFormError("message","Có lỗi xảy ra khi thêm vào database.");
            }
        }
    }

    function draw()
    {
        global $display;
        $display->add("WEB_ROOT",WEB_ROOT);
        $display->add("WEB_DIR",WEB_DIR);

        $this->beginForm(true);

        $act 		= Url::get("act");
        $id 		= Url::get("id");

        $hotel 		= $this->hotel;



        $display->add("hotel_id",			$hotel['id']);

        $display->add("hotel_name",			stripslashes(Url::get('hotel_name',$hotel['name'])));
        $display->add("hotel_pos",			stripslashes(Url::get('hotel_pos',$hotel['pos'])));

        $display->add('hotel_status', 			array(1=>"Hiện",2=>"Ẩn"));
        $display->add("status_id",				Url::get('hotel_status',$hotel['status']));



        $display->add("title","Sửa Menu");
        $display->add("title_submit","Sửa");

        $display->add("message",$this->showFormErrorMessages(1));
        $display->add("success",$this->showFormSuccesMessages(1));

        $display->output("HotelForm");

        $this->endForm();
    }

    function get_data_checkbox()
    {
        $features_checkbox_name = array();
        $features = array();
        $features_group = Db_Filter::getHotelFilersGroup();

        foreach($features_group as $value)
        {
            $id = $value['id'];
            $features_temp = Db_Filter::getHotelFilersByGroupId($id);

            foreach($features_temp as $v){
                $features[$id][$v['id']] = $v['name'];
            }

            $features_checkbox_name[$id] = "chb_features_".$id;
        }
        return array("features_group"=>$features_group,"features_checkbox_name"=>$features_checkbox_name,"features"=>$features);
    }
}
?>